package Scene5;
import Picture.GameImage;
import java.awt.image.BufferedImage;
import java.util.ArrayList;

public class Ice6 {
        int flag = 0;
        int dir = 1;
        int speed = 0;
        int x = 3800;
        int y = 840;
        ArrayList<BufferedImage> arrayListRight = new ArrayList<>();
        ArrayList<BufferedImage> arrayListLeft = new ArrayList<>();
        int indexL = 0;
        int indexR = 0;
        JumpAnimal jumpAnimal;
        BufferedImage img = GameImage.get("/Picture/fish.gif");
        int w = img.getWidth();
        int h = img.getHeight();
        public Ice6(JumpAnimal jumpAnimal){
            this.jumpAnimal = jumpAnimal;

            for (int i = 1; i < 13; i++) {
                arrayListLeft.add(GameImage.get("/Picture/鱼/朝向左/"+i+".png"));
            }
            for (int i = 1; i < 13; i++) {
                arrayListRight.add(GameImage.get("/Picture/鱼/朝向右/"+i+".png"));
            }
        }
    public void changeImage(){
        if(indexL==12){
            indexL = 0;
        }
        if(indexR==12){
            indexR = 0;
        }
        if(dir == 1){
            img = arrayListLeft.get(indexL);
            indexL++;
        }
        if(dir == 2){
            img = arrayListRight.get(indexR);
            indexR++;
        }

    }

        public void move() {
            if (x - jumpAnimal.x <= 1000||flag==1) {
                flag = 1;
                jumpAnimal.sign = 1;
                newMove();

            } else if(flag==0) {
                if (jumpAnimal.y == jumpAnimal.groundY) {
                    speed = 0;
                }
                x -= speed / 2;
            }
        }
        private void newMove() {
            if(jumpAnimal.x>x&&jumpAnimal.x<x+w&&jumpAnimal.y==jumpAnimal.groundY){
                dir = 2;
                x+=20;
            }
            else {
                if (dir == 1) {
                    x -= 20;
                } else {
                    x += 20;
                }
                if (x < 700) {
                    dir = 2;
                }
                if (x > 1400) {
                    dir = 1;
                }
            }
        }
    public void  reOpen(){
         flag = 0;
         dir = 1;
         speed = 0;
         x = 3800;
         y = 840;
    }

    }

